<?

//判断token是否存在
if (!$_SESSION['token']) {

//配置参数的数组
    $CONF = array(
        '__APPID__'    => 'wxf251770983aae256',
        '__SERECT__'   => 'e80c371e5c4d67853779943be238379d',
        '__CALL_URL__' => 'https://dj100.enpingshi.com/api/dangjian100/getopenid.php' //当前页地址
    );


    $getCodeUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential" .
        "&appid=" . $CONF['__APPID__'] .
        "&secret=" . $CONF['__SERECT__'];


    $token = substr(file_get_contents($getCodeUrl), 17,157);
}


    $_SESSION['token'] = $token;





exit;

#"&redirect_uri=" . $CONF['__CALL_URL__']  .
#"&response_type=code".
#"&scope=snsapi_base". #!!!scope设置为snsapi_base !!!
#"&state=1";

//跳转微信获取code值,去登陆
header('Location:' . $getCodeUrl);
 


$code     		=	trim($_GET['code']);




//使用code，拼凑链接获取用户openid
$getTokenUrl    =  "https://api.weixin.qq.com/sns/oauth2/access_token".
"?appid={$CONF['__APPID__']}".
"&secret={$CONF['__SERECT__']}".
"&code={$code}".
"&grant_type=authorization_code";


    $get_json=file_get_contents($getTokenUrl);
 

 


?>
</div>
